package net.wanho.commons.dao.impl;

import net.wanho.commons.dao.BaseDAO;
import net.wanho.commons.exception.DAOException;
import net.wanho.commons.exception.DataAccessException;
import net.wanho.commons.factory.BeanFactory;
import net.wanho.commons.util.JDBCTemplate;
import net.wanho.customerManage.po.LinkMan;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

public abstract class BaseDAOImpl<T> implements BaseDAO<T> {
    protected JDBCTemplate jdbcTemplate = BeanFactory.getBean(JDBCTemplate.class) ;
    //实体类的Class对象
    private Class  entityClass ;
    public BaseDAOImpl(){
        //动态获得 泛型 参数类型
        Type genType = this.getClass().getGenericSuperclass();
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
        entityClass =  (Class)params[0];
    }

    // 查询返回多行 二次包装 【少填一个参数】
    protected List<T> queryForList(String sql, Object ... params) throws DataAccessException{
        return jdbcTemplate.queryForList(sql,entityClass,params) ;
    }

    // 查询返回一行 二次包装 【少填一个参数】
    protected T queryForObject(String sql, Object ... params) throws DataAccessException{
        return jdbcTemplate.queryForObject(sql,entityClass,params) ;
    }

    @Override
    public boolean insert(T entity) throws DAOException {
        return false;
    }

    @Override
    public boolean update(T entity) throws DAOException {
        return false;
    }

    @Override
    public T findById(String id) throws DAOException {
        return null;
    }

    @Override
    public List<T> selectAll() throws DAOException {
        return null;
    }

    @Override
    public List<T> selectByCond(Map<String, String> condMap) throws DAOException {
        return null;
    }

    @Override
    public boolean delete(String id) throws DAOException {
        return false;
    }
}
